﻿/*
Copyright (c) 2010 Lance Ward
This software is licensed under the MIT license, except where otherwise noted.
For complete license details, refer to license.txt
*/

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ADNColorPicker
{
    public partial class ColorStrip : UserControl
    {
        private int stripHeight = 20;
        private int stripWidth = 100;
        private Image stripImage = null;
		private ColorRangeType type = ColorRangeType.A;
		public event EventHandler ColorChanged;	//a mirror of GradientRange color changed

        public ColorStrip()
        {
            InitializeComponent();
        }

		public Color BaseColor
		{
			get { return colorRange.BaseColor; }
			set { colorRange.BaseColor = value; }
		}

        public ColorRangeType Type
        {
            get
            {
                return type;
            }
            set
            {
				type = value;
				this.colorRange.Type = type;
                lblStrip.Text = type.ToString();
            }
        }

        public int StripHeight
        {
            get
            {
                return stripHeight;
            }
            set
            {
                stripHeight = value;
            }
        }

        public int StripWidth
        {
            get
            {
                return stripWidth;
            }
            set
            {
                stripWidth = value;
            }
        }

        public Image StripImage
        {
            get
            {
                return stripImage;
            }
            set
            {
                stripImage = value;
            }
        }

		//this is fired if the spinner is used to change the color
		//or if the slider is used to change the color
		private void OnColorChanged()
		{
			if (ColorChanged != null) { ColorChanged(this, EventArgs.Empty); }
		}

        private void IntializeStrip()
        {

            stripImage = new Bitmap(stripWidth, stripHeight);
        }

		private void gradientRange_ColorChanged(object sender, EventArgs e)
		{
			//reset the spinner
			//fire ColorChanged event
			if (spinAlpha.Value != colorRange.Value) { spinAlpha.Value = colorRange.Value; }
			OnColorChanged();
		}

		private void spinAlpha_ValueChanged(object sender, EventArgs e)
		{
			//reset the gradientrange
			//fire colorchanged event

			if (colorRange.Value != spinAlpha.Value) { colorRange.Value = (int)spinAlpha.Value; }
			OnColorChanged();
		}
    }
}
